package com.maila.xiaoaoschool.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.maila.xiaoaoschool.R;
import com.maila.xiaoaoschool.entity.XAmallGoods;
import com.maila.xiaoaoschool.util.Constants;
import com.zhy.autolayout.AutoRelativeLayout;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by mark on 2017/9/29.
 */

public class MallAdapter extends BaseAdapter {
    Context context;
    List<XAmallGoods.DataBean> mdata;
    public MallAdapter(Context context) {
        this.context = context;
        mdata=new ArrayList<>();
    }

    public List<XAmallGoods.DataBean> getMdata() {
        return mdata;
    }

    public void setMdata(List<XAmallGoods.DataBean> mdata) {
        this.mdata = mdata;
        notifyDataSetChanged();
    }
    public void addMdata(List<XAmallGoods.DataBean> mdata) {
        this.mdata.addAll(mdata) ;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_mall, viewGroup, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
            AutoUtils.autoSize(view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        Glide.with(context).load(Uri.parse(Constants.URL_ROOT_XIAOAO+mdata.get(i).getGoods_img())).into(holder.ivGoods);
        holder.tvGoodName.setText(mdata.get(i).getGoods_name());
        holder.tvGoodPrice.setText(mdata.get(i).getGoods_price());
        return view;
    }


    static class ViewHolder {
        @BindView(R.id.iv_goods)
        ImageView ivGoods;
        @BindView(R.id.tv_good_name)
        TextView tvGoodName;
        @BindView(R.id.tv_good_price)
        TextView tvGoodPrice;
        @BindView(R.id.tv_shop_name)
        TextView tvShopName;
        @BindView(R.id.arl_cash)
        AutoRelativeLayout arlCash;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
